#include <stdio.h>
#include "spi.h"
typedef unsigned char u8;
int main(int argc, char **argv)
{
	char *device = "/dev/spidev1.0";
	int ret = 0;
	int i = 0;
	u8 tx[6] = {0x00, 0x84, 0x00, 0x10, 0x00, 0x00};
	u8 rx[512] = {0};
	
	if(argc > 1){
		device = argv[1];
	}
	spi_t spi;
	ret = spi_open(&spi, device, 0, 150000);
	if(ret < 0){
		printf("SpiInit failed \n");
		return -1;
	}
	char str[512] = {0};
	spi_tostring(&spi, str, sizeof(str));
	printf("spi string : %s \n", str);
	
	printf("write data: ");
	for(i=0; i<6; i++)
		printf("%#x ",tx[i]);
	printf("\r\n");
	ret = spi_transfer(&spi, tx, rx, 6);
	if(ret < 0){
		printf("spi transfer failed \n");
	}else{
		printf("spi transfer OK : ");
		for(i=0; i<6; i++){
			printf("%d ", rx[i]);
		}
		printf("\n");
	}
	
	spi_close(&spi);
	return -1;
}
